Memcached : Use it on Python
2016/09/11 |
This is the example to use Memcached on Python.
|
|
[1] | Install Python Memcached Client Library. |
root@dlp:~# apt-get -y install python-memcache
|
[2] | Basic usage on Python. |
ubuntu@dlp:~$
vi use_memcache.py #!/usr/bin/env python import memcache client = memcache.Client(["127.0.0.1:11211"], cache_cas=True) # set and get a Key client.set("key01", "value01") print "key01.value :", client.get("key01") # append and get a Key client.append("key01", ",value02") print "key01.value :", client.get("key01") client.set("key02", 1) # increment client.incr("key02", 100) print "key02.value :", client.get("key02") # decrement client.decr("key02", 51) print "key02.value :", client.get("key02") # CAS client.set("key03", "value03") print "key03.value :", client.gets("key03") print "key03.casid :", client.cas_ids["key03"] client.cas("key03", "value04") print "key03.value :", client.gets("key03") # run ubuntu@dlp:~$ python use_memcache.py key01.value : value01 key01.value : value01,value02 key02.value : 101 key02.value : 50 key03.value : value03 key03.casid : 297 key03.value : value04 |